package org.it2.Dominio;

import java.util.Vector;

import org.it2.Control.SingletonAgent;
import org.it2.Control.InterfaceAgent;
import org.it2.Control.ResourceType;
import org.it2.Control.DBResource;

public class TareaBDManager {

	public static boolean insert(TareaBD tarea) {
		try {
			InterfaceAgent agent = SingletonAgent.getAgent();

	        String sql = "INSERT INTO recordatorios(titulo, completado, fechaLimite, fechaCreada, idusuarios) VALUES ( ?, ?, ?, ?, ?);";

	        Vector<DBResource> resourceList= new Vector<DBResource>();
	        resourceList.add(new DBResource(ResourceType.STRING, tarea.getNombre()));
	        resourceList.add(new DBResource(ResourceType.BOOLEAN, tarea.isCompletada()));
	        resourceList.add(new DBResource(ResourceType.DATE, tarea.getFechaFin()));
	        resourceList.add(new DBResource(ResourceType.DATE, tarea.getFechaInicio()));
	        resourceList.add(new DBResource(ResourceType.INT, tarea.getAutorBD().getId()));
	        System.out.println("Antes de modificación");
	        int res = agent.modifyWithID(sql, resourceList);
	        tarea.setId(res);
	        System.out.println("Modificado");
	        if (res != -1){
	        	System.out.println("True");
	            return true;
	        }
	        System.out.println("False");
	    } catch ( Exception e) {
	        int sd = 0;
	        System.out.println("Excepcion: " + e.getMessage());
	    }

	    return false;
	}
}